package com.fbs.wowo.essay.web;

import com.fbs.wowo.base.BaseController;
import com.fbs.wowo.base.Response;
import com.fbs.wowo.essay.entity.Essay;
import com.fbs.wowo.essay.entity.EssayInfoResponse;
import com.fbs.wowo.essay.entity.EssayListResponse;
import com.fbs.wowo.essay.service.EssayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("essay")
public class EssayController extends BaseController {

    @Resource
    private EssayService essayService;

    /**
     * 添加图文
     */
    @PostMapping("insertEssay")
    public Response insertEssay(Essay essay) {
        return success(essayService.insertSelective(essay));
    }

    /**
     * 推荐列表
     */
    @GetMapping("recList")
    public Response recList(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<EssayListResponse> recList = essayService.findRecommendList();
        PageInfo<EssayListResponse> page = new PageInfo<>(recList);
        return success(page);
    }











    /**
     * 删除图文
     */
    @PostMapping("deleteEssay")
    public Response deleteEssay(String essayId,String userId) {
        int i = essayService.deleteByPrimaryKey(essayId,userId);
        if (i!=0){
            return success();
        }else{
            return failed("数据不存在");
        }
    }

    /**
     * 编辑页面
     */
    @PostMapping("updateEssay")
    public Response updateEssay(Essay essay) {
        essayService.updateByPrimaryKeySelective(essay);
        return success();
    }

    /**
     * 获取详情
     * @return
     */
    @GetMapping("findEssayInfo")
    public Response findEssayInfo(String essayId,String uId){
        EssayInfoResponse essayInfo = essayService.findEssayInfo(essayId, uId);
        return success(essayInfo);
    }



    /**
     * 查询我的作品的待上传的图文和音频的个数
     */
    @GetMapping("findMyEssayNum")
    public Response findMyEssayNum(String userId){
        return success(essayService.findMyEssayNum(userId));
    }

    /**
     * 确权的人的用户名称的列表
     */
    @GetMapping("confirmedUserList")
    public Response confirmedUserList(){
        return success(essayService.confirmedUserList());
    }

    /**
     *  别人主页
     */
    @GetMapping("findUserHome")
    public Response findUserHome(String loginUserId,String userId) {
        return success(essayService.findUserHomeByUserId(loginUserId, userId));
    }

    /**
     * 个人主页
     */
    @GetMapping("findNomHome")
    public Response findNomHome(String userId) {
        return success(essayService.oneselfHomeByUserId(userId));
    }

    /**
     * 根据分类类型查询图文列表
     */
    @GetMapping("findEssayByClassifyId")
    public Response findEssayByClassifyId(String classifyId, int type) {
        return success(essayService.findEssayByClassifyId(classifyId,type));
    }
}
